import { cookies, db, log, title, open, traversalTree } from '@csii/vx-util';
/**
 * script处理
 */
function stripScript(content) {
  const result = content.match(/<(script)>([\s\S]+)<\/\1>/);
  return result && result[2] ? result[2].trim() : '';
}
/**
 * style样式处理
 */
function stripStyle(content) {
  const result = content.match(/<(style)\s*>([\s\S]+)<\/\1>/);
  return result && result[2] ? result[2].trim() : '';
}
/**
 * 编写例子时不一定有 template。所以采取的方案是剔除其他的内容
 */
function stripTemplate(content) {
  content = content.trim();
  if (!content) {
    return content;
  }
  return content.replace(/<(script|style)[\s\S]+<\/\1>/g, '').trim();
}

//JSON转换存在循环引用解决函数
function replacerFunc(value) {
  const visited = new WeakSet();
  if (typeof value === "object" && value !== null) {
    if (visited.has(value)) {
      return;
    }
    visited.add(value);
  }
  return value;
}
//关闭当前标签页导航
function closeNowPage(params) {
  let nowPage = params.$store.getters.nowPage
  let tagsView = params.$parent.$children[0]
  tagsView.closeSelectedTag(nowPage)
}
const util = {
  stripScript,
  stripStyle,
  stripTemplate,
  cookies,
  db,
  log,
  title,
  open,
  traversalTree,
  replacerFunc,
  closeNowPage
};

export default util;
